﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SmallJob.Model;
using SmallJob.Data;
using SmallJob.Services.Interfaces;
using SmallJob.Data.Interfaces;
using SmallJob.Services.Code;

namespace SmallJob.Services.Implements
{
    public class BannerService: RepositoryBase<Banner>,IBannerService
    {
        public BannerService(IDatabaseFactory DbFactory) : base(DbFactory) { }
        
        public List<Banner> GetByPage(int page, int pagesize, out int total)
        {
            var list = from r in SmallJobDB.Banners
                       orderby r.ID descending
                       select r;
            int skip = (page - 1) * pagesize;
            total = list.ToList().Count;
            return list.Skip(skip).Take(pagesize).ToList();
        }
        public List<Banner> GetAllBannerUse()
        {
            var lst = from b in All()
                      where b.IsUse==true
                      orderby b.DisplayNumber ascending
                      select b;
            return lst.ToList();
        }
        public List<Banner> GetForSlider()
        {
            var list = from b in SmallJobDB.Banners
                       where b.IsUse == true
                       orderby b.DisplayNumber ascending
                       select b;
            return list.ToList();
        }


        public List<Banner> GetByPageFilter(int page, int pagesize, out int total, string filter)
        {
            int skip = (page - 1) * pagesize;
            var list = (from d in SmallJobDB.Banners
                        where d.Title.Contains(filter) ||d.Description.Contains(filter)
                        orderby d.ID descending
                        select d);

            total = list.ToList().Count;
            var alist = list.ToList();
            return list.Skip(skip).Take(pagesize).ToList();
        }
    }
}
